﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Warehouse.DataAccess
{
    public partial class Permission : CustomeEntity<Permission>
    {
        public static Permission[] GetPermissions()
        {
            using (WarehouseClassesDataContext context = new WarehouseClassesDataContext())
            {
                return (from m in context.Permission select m).ToArray();
            }
        }

        public static Dictionary<string, int> GetPermissionDic()
        {
            using (WarehouseClassesDataContext context = new WarehouseClassesDataContext())
            {
                var ps = (from p in context.Permission
                          from m in context.Module
                          where p.ModuleID == m.ID
                          select new
                          {
                              PID = p.ID,
                              ActionName = m.Name + "-" + p.ActionName
                          }).ToList();

                Dictionary<string, int> pDics = new Dictionary<string, int>();
                if (ps != null)
                {
                    foreach (var item in ps)
                    {
                        pDics.Add(item.ActionName, item.PID);
                    }
                }
                return pDics;
            }
        }

        protected override System.Linq.Expressions.Expression<Func<Permission, bool>> GetPredicate()
        {
            return p => p.ID == this.ID;
        }
    }
}
